<?php
/**
 * Created by PhpStorm.
 * User: huynguyen
 * Date: 9/26/14
 * Time: 8:10 PM
 */

namespace Common\Forms;


class BaseForm extends \Phalcon\Forms\Form
{
    public function renderDecorated($name)
    {
        $element = $this->get($name);
        $messages = $this->getMessagesFor($element->getName());
        $hasError = '';
        $messagesError = '';
        $html = '';

        if(count($messages))
        {
            $hasError = ' has-error';
            foreach ($messages as $message) {
                $messagesError .= $message;
            }
        }
        switch($name)
        {
            case 'csrf':
            case 'id':
                //case 'submit':
                $html .= $this->render($name);
                break;
            /*
            case 'file':
                $html .= '<div class="form-group col-md-12 col-sm-3 col-md-offset-3' . $hasError . '">';
                $html .= '<div class="col-md-2"><label for="">' . $element->getLabel() . '</label></div>';
                $html .= '<div class="col-md-8">';
                $html .= '<span class="btn btn-success fileinput-button"><i class="glyphicon glyphicon-plus"></i><span>Select files...</span>';
                $html .= $this->render($name);
                $html .= '</span>';
                $html .= '<div id="progress" class="progress"><div class="progress-bar progress-bar-success"></div></div>';
                $html .= '<div id="files" class="files"></div>';
                $html .= '<div class="clearfix"><div class="help-block">' . $messagesError . '</div></div>';
                $html .= '</div></div>';
                break;*/
            default:
                $html .= '<div class="form-group col-md-12 col-sm-3 col-md-offset-3' . $hasError . '">';
                $html .= '<div class="col-md-2"><label for="">' . $element->getLabel() . '</label></div>';
                $html .= '<div class="col-md-8">';
                $html .= $this->render($name);
                $html .= '<div class="clearfix"><div class="help-block">' . $messagesError . '</div></div>';
                $html .= '</div></div>';
                break;
        }
        return $html;
    }
} 